package com.cx.service.impl;

import com.cx.dao.ClubMapper;
import com.cx.pojo.Club;
import com.cx.pojo.User;
import com.cx.service.ClubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClubServiceImpl implements ClubService {

    @Autowired
    private ClubMapper clubMapper;

    //    根据用户id查询加入的社团信息
    @Override
    public List<Club> getAllClubById(Integer id) {
        return clubMapper.getAllClubById(id);
    }
    //根据社团id退出
    @Override
    public void getDeleteClubById(Integer clubID, Integer id) {
        clubMapper.getDeleteClubById(clubID, id);
    }

    //    团队成员的基本信息情况的在线查询
    @Override
    public List<User> getClubByIdList(Integer id) {
        return clubMapper.getClubByIdList(id);
    }

    @Override
    public void addClub(Club club) {
        clubMapper.addClub(club);
    }

    @Override
    public void clubAddUser(Integer clubID, Integer id) {
        if (clubMapper.clubAddUserById(clubID, id) == null) {
            clubMapper.clubAddUser(clubID, id);
        }

    }

    //    根据id删除指定的社团信息
    @Override
    public void deleteClubById(Integer id) {
        clubMapper.deleteClubById(id);

    }
    //        删除中间表的俱乐部用户
    @Override
    public void deleteClubTypeUseridById(Integer id) {
        clubMapper.deleteClubTypeUseridById(id);
    }

    @Override
    public void updateClub(Club club) {
        clubMapper.updateClub(club);
    }

    @Override
    public List<Club> getAllClub(Integer currentPage, Integer pageSize) {
        return clubMapper.getAllClub((currentPage - 1) * pageSize, pageSize);
    }

    @Override
    public Club getClubById(Integer id) {
        return clubMapper.getClubById(id);
    }

    @Override
    public int count() {
        return clubMapper.count();
    }

    @Override
    public boolean checkName(String name) {
        boolean flag = false;
        Club club = clubMapper.checkName(name);
        if (club != null) {
            flag = true;
        }
        return flag;
    }
}
